本文介绍在AWS EC2上部署OSQA,使用环境是:Ubuntu+apache+MySQL。

1. 安装Python模块

OSQA是用Python编写的,安装Python一些模块,相关命令如下:

sudo apt-get install python-setuptools  # python-setuptools包含easy_install 

# 安装Python其他模块
sudo easy_install ElementTree Markdown html5lib python-openid
sudo apt-get install python-mysqldb   # sudo easy_install mysql-python

sudo apt-get install python-django
sudo apt-get install libapache2-mod-wsgi  # 安装mod-wsgi, sudo a2enmod mod-wsgi

#sudo vim /etc/apache2/apache2.conf  # 这一步,个人认为没必要
#added by sparkandhsine, 
#LoadModule wsgi_module modules/mod_wsgi.so

安装South,时间有些久了,忘了装这个干嘛了,囧。

# South ships with a full database-agnostic API for performing schema changes on databases, much like Django’s ORM provides data manipulation support.
sudo apt-get install python-pip
sudo pip install south

2. 创建数据库

(1)下载源代码

/var/www/$ git clone https://github.com/OSQA/osqa.git

(2)新建一个数据库

mysql -u root -p

# 输入密码
create database osqa DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

(3)生成数据库内容

/var/www/osqa/目录下运行命令python manage.py syncdb自动生成osqa数据库,如下:

/var/www/osqa$ python manage.py syncdb
......
You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): no
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)

3. 配置OSQA

(1)创建osqa.wsgi文件

拷贝osqa.wsgi.distosqa.wsgi

$cp osqa.wsgi.dist osqa.wsgi

修改osqa.wsgisys.path.append

# osqa.wsgi文件内容如下:
import os
import sys
sys.path.append('/var/www')
sys.path.append('/var/www/osqa')
# The first part of this module name should be identical to the directory name
# of the OSQA source.  For instance, if the full path to OSQA is
# /home/osqa/osqa-server, then the DJANGO_SETTINGS_MODULE should have a value
# of 'osqa-server.settings'.
os.environ['DJANGO_SETTINGS_MODULE'] = 'osqa.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

(2)创建settings_local.py文件

$cp settings_local.py.dist settings_local.py
$vi settings_local.py

# settings_local.py需要修改的内容如下:

DATABASES = { 
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'osqa',
        'USER': 'root',
        'PASSWORD': '**********',
        'HOST': '',
        'PORT': '',
        'CONN_MAX_AGE': 600,
    }
}

APP_URL = 'http://www.tobediff.com

LANGUAGE_CODE = 'zh_CN'

ALLOWED_HOSTS = ('tobediff.com',)

4. Web服务器配置文件

/etc/apache2/sites-available/目录下创建配置文件osqa.conf,对着000-default.conf修改,最后内容如下(以tobediff.com为例):

# Must be readable and writable by apache
WSGISocketPrefix ${APACHE_RUN_DIR}

#NOTE: all urs below will need to be adjusted if
#settings.FORUM_SCRIPT_ALIAS !='' (e.g. = 'forum/')
#this allows "rooting" forum at [http://example.com/forum], if you like
<VirtualHost *:80>
    ServerAdmin admin@tobediff.com
    DocumentRoot /var/www/osqa
    ServerName tobediff.com

    #run mod_wsgi process for django in daemon mode
    #this allows avoiding confused timezone settings when
    #another application runs in the same virtual host
    WSGIDaemonProcess OSQA
    WSGIProcessGroup OSQA

    #force all content to be served as static files
    #otherwise django will be crunching images through itself wasting time
    Alias /m/ "/var/www/osqa/forum/skins/"
    <Directory "/var/www/osqa/forum/skins">
        Require all granted
    </Directory>

    Alias /upfiles/ "/var/www/osqa/forum/upfiles/"
    <Directory "/var/www/osqa/forum/upfiles">
        Require all granted 
    </Directory>

    #this is your wsgi script described in the prev section
    WSGIScriptAlias / /var/www/osqa/osqa.wsgi

    CustomLog ${APACHE_LOG_DIR}/osqa.access.log common
    ErrorLog ${APACHE_LOG_DIR}/osqa.error.log
</VirtualHost>

启用设置文件:

sudo a2ensite osqa.conf
sudo service apache2 restart

5. 修改hosts文件

打开/etc/hosts文件,在文件末尾添加如下内容:

# added by sparkandshine
# xx.xx.xx.xx为AWS EC2 Elastic IP
xx.xx.xx.xx tobediff.com

6. 修改DNS解析

zhilitea.com的A记录@解析到xx.xx.xx.xx(为AWS EC2 Elastic IP)。

@ --> xx.xx.xx.xx  # xx.xx.xx.xx为AWS EC2 Elastic IP

PS: 若不能正常访问,可以查看错误日志文件/var/log/apache2/osqa.error.log

7. 遇到问题及解决

7.1 500 Sever Error

安装完访问提示错误: 500 Server Error。产生这个问题的原因是markdown版本太高导致的不兼容,解决方法就是使用低版本的markdown,命令如下:

sudo pip install Markdown==2.4.1

7.2 Internal Server Error

查看了错误日志,部分内容如下:

mod_wsgi (pid=2131): Exception occurred processing WSGI script '/var/www/osqa/osqa.wsgi'.

解决问题可能在这里: (睡了,改天再整)

参考资料:

[1] GitHub: OSQA INSTALL

[2] 博文《OSQA搭建部署(centos6,apache,mysql,wsgi)》

[3] 博文《Linux + Apache + MySQL 环境下OSQA部署

[4] Blog: Configuring www folder on Ubuntu (Amazon EC2)

本文系Spark & Shine原创,转载需注明出处本文最近一次修改时间 2022-04-15 15:33

results matching ""

    No results matching ""